package com.elhakimz.matra.util;

import com.jme.scene.Node;
import com.jme.scene.Line;
import com.jme.scene.state.TextureState;
import com.jme.scene.shape.Box;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.util.TextureManager;
import com.elhakimz.matra.actor.ActorGL;
import com.elhakimz.matra.MatraSystem;

/**
 * Created by IntelliJ IDEA.
 * User: abiel
 * Date: Feb 14, 2010
 * Time: 9:26:43 PM
 * To change this template use File | Settings | File Templates.
 */
public class SceneUtil {
    public static Node CreateGrid(int xwidth, int ywidth, int step){

       Node gridNode = new Node("gridNode");

          int xwidth2= xwidth / 2;
          int ywidth2= ywidth / 2;

          // Gitternetz
          for (int x = -xwidth2; x <= xwidth2; x=x+step) {
              Line l = new Line("xLine" + x, new Vector3f[]{new Vector3f((float) x, 0.1f, - xwidth2), new Vector3f((float) x, 0.1f, xwidth2)}, null, null, null);

              if(Math.abs(x) % 100==0){
                  l.setSolidColor(ColorRGBA.white);
                  System.out.println("WHITE");
              }else{
                  l.setSolidColor(ColorRGBA.darkGray);
              }
              l.setModelBound(new BoundingBox());
              l.updateModelBound();
              l.setCastsShadows(false);
              gridNode.attachChild(l);
          }

          for (int z = -ywidth2; z <= ywidth2; z=z+step) {
              Line l = new Line("zLine" + z, new Vector3f[]{new Vector3f(-ywidth2, 0.1f, (float) z), new Vector3f(ywidth2, 0.1f, (float) z)}, null, null, null);
              if(Math.abs(z) % 100==0){
                           l.setSolidColor(ColorRGBA.white);
                           System.out.println("WHITE");
                       }else{
                           l.setSolidColor(ColorRGBA.darkGray);
                       }
                       l.setModelBound(new BoundingBox());
              l.updateModelBound();
              l.setCastsShadows(false);
              gridNode.attachChild(l);
          }

          System.out.println("X-AXIS ROTATION");// rote x-Achse
          final Line xAxis = new Line("xAxis", new Vector3f[]{new Vector3f(-xwidth2, 0.1f, 0f), new Vector3f(xwidth2, 0.1f, 0f)}, null, null, null);
          xAxis.setModelBound(new BoundingBox());
          xAxis.updateModelBound();
          xAxis.setSolidColor(ColorRGBA.red);
          xAxis.setCastsShadows(false);
          gridNode.attachChild(xAxis);

          // blaue z-Achse
          System.out.println("Z-AXIS ROTATION");// rote x-Achse
          final Line zAxis = new Line("zAxis", new Vector3f[]{new Vector3f(0f, 0.1f, -ywidth2), new Vector3f(0f, 0.1f, ywidth2)}, null, null, null);
          zAxis.setModelBound(new BoundingBox());
          zAxis.updateModelBound();
          zAxis.setSolidColor(ColorRGBA.blue);
          zAxis.setCastsShadows(false);
          gridNode.attachChild(zAxis);

          return gridNode;
      }

    public static Node CreatePlane(){
            Node node = new Node("tacopsNode");
            Box box = new Box("tacopsPlane",new Vector3f(-500, 0.0f, -500),
                          new Vector3f(500, 0.0f, 500));
            box.setDefaultColor(ColorRGBA.blue);
            box.setModelBound(new BoundingBox());
            box.updateModelBound();

            node .attachChild(box);
            return node;
    }



     public static Node CreateOcean(){
            Node node = new Node("oceanNode");
            Box box = new Box("oceanPlane",new Vector3f(-500, 0.0f, -500),
                          new Vector3f(500, 0.0f, 500));
            TextureState ts = MatraSystem.disp.getRenderer().createTextureState();
        ts.setEnabled(true);
        ts.setTexture(
        TextureManager.loadTexture(
        ActorGL.class.getClassLoader().getResource(
        "jmetest/data/texture/water2.png"),
        Texture.MinificationFilter.BilinearNearestMipMap,
        Texture.MagnificationFilter.Bilinear));
        box.setRenderState(ts);

            node .attachChild(box);
          
            return node;
    }


    public static Node LoadScene(){
        return null;

    }

    
}
